
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1">
    <meta content=always name=referrer>
    <link rel="stylesheet" type="text/css" href="/static/mobile/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="/static/mobile/css/newbase.css">
    <script src="/static/mobile/js/jquery-1.8.2.js"></script>
    <title>浏览记录</title>
    <link rel="stylesheet" type="text/css" href="/static/mobile/js/layer_mobile/need/layer.css">
    <link rel="stylesheet" type="text/css" href="/static/mobile/js/layui/css/layui.css">
</head>
<body>
<div class="wrap-sc" style="overflow-x: hidden;">
    <header>
        <p>浏览记录</p>
        <img src="/static/mobile/img_user/back.png" class="back" onclick=window.location.href="/index.php/mobile/user_info/my_shop_index.html">
        <span><a href="javascript:empty();">清空</a> | <a href="javascript:change_display();" id="edit">编辑</a></span>
    </header>
    <div class="content">
        <div class="cur" id="show">
        </div>
    </div>
    <div class="footer" style="display: none;">
        <div class="all">
            <!--<div class="choose" id="zong"><a href="javascript:void(0);"><input type="checkbox" id="radio-1-3" name="radio-1-set"  class="radio allCk"/><label for="radio-1-3" onclick="check_all()">全选</label> </a></div>-->
            <div class="choose" id="zong"><a href="javascript:void(0);"><input type="checkbox" id="radio-1-3" name="radio-1-set" value="all"  class="radio allCk"/><label for="radio-1-3" >全选</label> </a></div>
            <div class="total" onclick="del()">
                <span class="settle">   删除   </span>
            </div>
        </div>
    </div>
</div>
<script src="/static/mobile/js/jquery-1.8.2.js"></script>
<script src="/static/mobile/js/jquery.form.min.js"></script>
<script src="/static/mobile/js/layer_mobile/layer.js"></script>
<script src="/static/mobile/js/layui/layui.js"></script>
<script src="/static/mobile/js/uploadPreview.js"></script>
<script src="/static/mobile/js/Validform_v5.3.2_min.js"></script>
<script src="/static/mobile/js/Validform_Datatype.js"></script>
<script src="/static/mobile/js/cart_price.js"></script>
<script src="/static/mobile/js/layui/layui.js"></script>
<script>
    //layer流加载
    layui.use('flow', function() {
        var $ = layui.jquery;
        var flow = layui.flow;
        flow.load({
            elem: '#show' //流加载容器
            ,isAuto:true
            ,isLazyimg:true
            ,done: function(page, next){ //执行下一页的回调
                var lis = [];
                var type = $('#type').val();
                $.ajax({
                    url:"/index.php/mobile/user_info/shop_browse.html",
                    dataType:'json',
                    type:'post',
                    data:{'page':page},
                    success:function(t){
                        layui.each(t.data, function(index, item){
                            var head = '<div class="time">'+index+'</div>';
                            var body = '';
                            for (var i=0;i<item.length;i++){
                                body +='<div class="tc" style="width: 100%;" id="show_'+item[i].id+'"><div class="choose" style="display:none" ><a href="javascript:void(0);">' +
                                    '<label for="radio-1-1"></label>' +
                                    '<input type="checkbox" name="radio-1-set" onclick="is_all_checked()" class="sun radio" value="'+item[i].id+'"/>' +
                                    '</a></div><div class="tc1"><div class="center" style=" padding: 5px  3% 5px 100px!important;">' +
                                    '<a href="javascript:jump_goods_details('+item[i].goods_id+');"><img src="/'+item[i].thumb_img+'" style="width: 90px;height: 90px;" onerror=this.src="/static/mobile/img/empty_img.png" width="98.55" ><div>' +
                                    '<h4>'+item[i].title+'</h4><div class="price">' +
                                    '<span>&yen;'+item[i].price+'</span></div></div></a></div></div></div>';
                            }
                            lis.push(head+body);
                        });
                        next(lis.join(''), page < t.pages);
                    },
                    error: function () {
                        layer.open({content:'网络繁忙,请重试',skin:'msg',time:2});
                    }
                })
            }
        });
    });
    //跳转到商品详情
    function jump_goods_details(id){
        sessionStorage.setItem('goods_url_back',window.location.href);
        window.location.href = "/index.php/mobile/user_category/goods_details.html?goods_id="+id;
    }
    function change_display(){
        $('.choose').not('#zong').toggle();
        $('.footer').toggle();
        var text = $('#edit');
        if (text.text() == '编辑'){
            text.text('完成');
        }else{
            text.text('编辑');
        }
    }
    //检测是否全选
    function is_all_checked(){
        var zhi = 0;
        $('.sun').each(function (i,o) {
            if ($(o).prop('checked')){
                zhi++;
            }
        });

        if (zhi == $('.sun').length){
            $('.allCk').prop('checked',true);
        }else{
            $('.allCk').prop('checked',false);
        }
    }
    //删除记录
    function del() {
        var shop_id = $('');
        var str = '';
        $('.radio:checked').each(function (i,o) {
            if (str == ''){
                str = $(o).val();
            }else {
                str += ','+$(o).val();
            }
        });
        var all = '';
        $('#radio-1-3:checked').each(function (i,o) {
            if (all == ''){
                all = $(o).val();
            }
        });
        if (str == ''){
            layer.open({content:'请选择删除项',skin:'msg',time:2});
        }else{
            layer.open({
                content: '您确定要删除吗？'
                ,btn: ['确定', '取消']
                ,yes: function(index){
                    var arr = str.split(",");
                    $.post("del_browse",{'id':str,'all':all},function (t) {
                        if (t.code == 200){
                            layer.open({content:t.message,skin:'msg',time:2});
                            for (var i=0;i<arr.length;i++){
                                $('#show_'+arr[i]).remove();
                            }
                            setTimeout("location.reload()",1000);
                        }else{
                            layer.open({content:t.message,skin:'msg',time:2});
                        }
                    });
                }
            });
        }
    }
    // 清空记录
    function empty(){
        layer.open({
            content: '您确定要清空记录吗？'
            , btn: ['确定', '取消']
            , yes: function (index) {
                $.ajax({
                    url:"empty_browse",
                    dataType:'json',
                    type:'post',
                    success:function (t) {
                        if (t.code == 200){
                            layer.open({content:t.message,skin:'msg',time:2});
                            //清空页面
                            $('#show').text('');
                        }else{
                            layer.open({content:t.message,skin:'msg',time:2});
                        }
                    },
                    error: function () {
                        layer.open({content:'网络繁忙,请重试',skin:'msg',time:2});
                    }
                });
            }
        });
    }
    //全选
    function check_all(){
//        console.log($('.allCk').prop('checked'));
        $('.radio').each(function (i,o) {
            $(o).prop('checked',!$('.allCk').prop('checked'));
        })
    }
    $('.allCk').click(function(){

        if($(this).is(':checked')){
            $('.radio').each(function(){
                //此处如果用attr，会出现第三次失效的情况
                $(this).prop("checked",true);
            });
        }else{
            $('.radio').each(function(){
                $(this).removeAttr("checked",false);
            });
        }

    });
</script>
</body>
</html>